# Try to find XCB on a Unix system
#
# This will define:
#
#   XCB_FOUND       - True if xcb is available
#   XCB_LIBRARIES   - Link these to use xcb
#   XCB_INCLUDE_DIR - Include directory for xcb
#   XCB_DEFINITIONS - Compiler flags for using xcb
#
# In addition the following more fine grained variables will be defined:
#
#   XCB_XCB_FOUND        XCB_XCB_INCLUDE_DIR        XCB_XCB_LIBRARIES
#   XCB_UTIL_FOUND       XCB_UTIL_INCLUDE_DIR       XCB_UTIL_LIBRARIES
#   XCB_COMPOSITE_FOUND  XCB_COMPOSITE_INCLUDE_DIR  XCB_COMPOSITE_LIBRARIES
#   XCB_DAMAGE_FOUND     XCB_DAMAGE_INCLUDE_DIR     XCB_DAMAGE_LIBRARIES
#   XCB_XFIXES_FOUND     XCB_XFIXES_INCLUDE_DIR     XCB_XFIXES_LIBRARIES
#   XCB_RENDER_FOUND     XCB_RENDER_INCLUDE_DIR     XCB_RENDER_LIBRARIES
#   XCB_RANDR_FOUND      XCB_RANDR_INCLUDE_DIR      XCB_RANDR_LIBRARIES
#   XCB_SHAPE_FOUND      XCB_SHAPE_INCLUDE_DIR      XCB_SHAPE_LIBRARIES
#   XCB_DRI2_FOUND       XCB_DRI2_INCLUDE_DIR       XCB_DRI2_LIBRARIES
#   XCB_GLX_FOUND        XCB_GLX_INCLUDE_DIR        XCB_GLX_LIBRARIES
#   XCB_SHM_FOUND        XCB_SHM_INCLUDE_DIR        XCB_SHM_LIBRARIES
#   XCB_XV_FOUND         XCB_XV_INCLUDE_DIR         XCB_XV_LIBRARIES
#   XCB_SYNC_FOUND       XCB_SYNC_INCLUDE_DIR       XCB_SYNC_LIBRARIES
#   XCB_XTEST_FOUND      XCB_XTEST_INCLUDE_DIR      XCB_XTEST_LIBRARIES
#   XCB_ICCCM_FOUND      XCB_ICCCM_INCLUDE_DIR      XCB_ICCCM_LIBRARIES
#   XCB_EWMH_FOUND       XCB_EWMH_INCLUDE_DIR       XCB_EWMH_LIBRARIES
#   XCB_IMAGE_FOUND      XCB_IMAGE_INCLUDE_DIR      XCB_IMAGE_LIBRARIES
#   XCB_RENDERUTIL_FOUND XCB_RENDERUTIL_INCLUDE_DIR XCB_RENDERUTIL_LIBRARIES
#   XCB_KEYSYMS_FOUND    XCB_KEYSYMS_INCLUDE_DIR    XCB_KEYSYMS_LIBRARIES
#
# Copyright (c) 2011 Fredrik Höglund <fredrik@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.


IF (NOT WIN32)
  IF (XCB_INCLUDE_DIR AND XCB_LIBRARIES)
    # In the cache already
    SET(XCB_FIND_QUIETLY TRUE)
  ENDIF (XCB_INCLUDE_DIR AND XCB_LIBRARIES)

  # Use pkg-config to get the directories and then use these values
  # in the FIND_PATH() and FIND_LIBRARY() calls
  FIND_PACKAGE(PkgConfig)
  PKG_CHECK_MODULES(PKG_XCB QUIET xcb xcb-util xcb-composite xcb-xfixes xcb-damage xcb-render xcb-randr
                                  xcb-shape xcb-dri2 xcb-glx xcb-shm xcb-xv xcb-sync
                                  xcb-xtest xcb-icccm xcb-ewmh xcb-image xcb-renderutil xcb-keysyms)

  SET(XCB_DEFINITIONS ${PKG_XCB_CFLAGS})

  FIND_PATH(XCB_XCB_INCLUDE_DIR         NAMES xcb/xcb.h             HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_UTIL_INCLUDE_DIR        NAMES xcb/xcb_util.h        HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_COMPOSITE_INCLUDE_DIR   NAMES xcb/composite.h       HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_XFIXES_INCLUDE_DIR      NAMES xcb/xfixes.h          HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_DAMAGE_INCLUDE_DIR      NAMES xcb/damage.h          HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_RENDER_INCLUDE_DIR      NAMES xcb/render.h          HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_RANDR_INCLUDE_DIR       NAMES xcb/randr.h           HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_SHAPE_INCLUDE_DIR       NAMES xcb/shape.h           HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_DRI2_INCLUDE_DIR        NAMES xcb/dri2.h            HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_GLX_INCLUDE_DIR         NAMES xcb/glx.h             HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_SHM_INCLUDE_DIR         NAMES xcb/shm.h             HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_XV_INCLUDE_DIR          NAMES xcb/xv.h              HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_SYNC_INCLUDE_DIR        NAMES xcb/sync.h            HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_XTEST_INCLUDE_DIR       NAMES xcb/xtest.h           HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_ICCCM_INCLUDE_DIR       NAMES xcb/xcb_icccm.h       HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_EWMH_INCLUDE_DIR        NAMES xcb/xcb_ewmh.h        HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_IMAGE_INCLUDE_DIR       NAMES xcb/xcb_image.h       HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_RENDERUTIL_INCLUDE_DIR  NAMES xcb/xcb_renderutil.h  HINTS ${PKG_XCB_INCLUDE_DIRS})
  FIND_PATH(XCB_KEYSYMS_INCLUDE_DIR     NAMES xcb/xcb_keysyms.h     HINTS ${PKG_XCB_INCLUDE_DIRS})

  FIND_LIBRARY(XCB_XCB_LIBRARIES         NAMES xcb              HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_UTIL_LIBRARIES        NAMES xcb-util         HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_COMPOSITE_LIBRARIES   NAMES xcb-composite    HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_DAMAGE_LIBRARIES      NAMES xcb-damage       HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_XFIXES_LIBRARIES      NAMES xcb-xfixes       HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_RENDER_LIBRARIES      NAMES xcb-render       HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_RANDR_LIBRARIES       NAMES xcb-randr        HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_SHAPE_LIBRARIES       NAMES xcb-shape        HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_DRI2_LIBRARIES        NAMES xcb-dri2         HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_GLX_LIBRARIES         NAMES xcb-glx          HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_SHM_LIBRARIES         NAMES xcb-shm          HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_XV_LIBRARIES          NAMES xcb-xv           HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_SYNC_LIBRARIES        NAMES xcb-sync         HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_XTEST_LIBRARIES       NAMES xcb-xtest        HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_ICCCM_LIBRARIES       NAMES xcb-icccm        HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_EWMH_LIBRARIES        NAMES xcb-ewmh         HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_IMAGE_LIBRARIES       NAMES xcb-image        HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_RENDERUTIL_LIBRARIES  NAMES xcb-render-util  HINTS ${PKG_XCB_LIBRARY_DIRS})
  FIND_LIBRARY(XCB_KEYSYMS_LIBRARIES     NAMES xcb-keysyms      HINTS ${PKG_XCB_LIBRARY_DIRS})

  set(XCB_INCLUDE_DIR ${XCB_XCB_INCLUDE_DIR} ${XCB_UTIL_INCLUDE_DIR} ${XCB_COMPOSITE_INCLUDE_DIR}
          ${XCB_XFIXES_INCLUDE_DIR} ${XCB_DAMAGE_INCLUDE_DIR} ${XCB_RENDER_INCLUDE_DIR}
          ${XCB_RANDR_INCLUDE_DIR} ${XCB_SHAPE_INCLUDE_DIR} ${XCB_DRI2_INCLUDE_DIR}
          ${XCB_GLX_INCLUDE_DIR} ${XCB_SHM_INCLUDE_DIR} ${XCB_XV_INCLUDE_DIR}
          ${XCB_SYNC_INCLUDE_DIR} ${XCB_XTEST_INCLUDE_DIR} ${XCB_ICCCM_INCLUDE_DIR}
          ${XCB_EWMH_INCLUDE_DIR} ${XCB_IMAGE_INCLUDE_DIR} ${XCB_RENDERUTIL_INCLUDE_DIR}
          ${XCB_KEYSYMS_INCLUDE_DIR})

  set(XCB_LIBRARIES ${XCB_XCB_LIBRARIES} ${XCB_UTIL_LIBRARIES} ${XCB_COMPOSITE_LIBRARIES}
          ${XCB_XFIXES_LIBRARIES} ${XCB_DAMAGE_LIBRARIES} ${XCB_RENDER_LIBRARIES}
          ${XCB_RANDR_LIBRARIES} ${XCB_SHAPE_LIBRARIES} ${XCB_DRI2_LIBRARIES} ${XCB_GLX_LIBRARIES}
          ${XCB_SHM_LIBRARIES} ${XCB_XV_LIBRARIES} ${XCB_SYNC_LIBRARIES} ${XCB_XTEST_LIBRARIES}
          ${XCB_ICCCM_LIBRARIES} ${XCB_EWMH_LIBRARIES} ${XCB_IMAGE_LIBRARIES}
          ${XCB_RENDERUTIL_LIBRARIES}  ${XCB_KEYSYMS_LIBRARIES})

  list(REMOVE_DUPLICATES XCB_INCLUDE_DIR)

  include(FindPackageHandleStandardArgs)

  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB             DEFAULT_MSG  XCB_LIBRARIES             XCB_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_XCB         DEFAULT_MSG  XCB_XCB_LIBRARIES         XCB_XCB_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_UTIL        DEFAULT_MSG  XCB_UTIL_LIBRARIES        XCB_UTIL_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_COMPOSITE   DEFAULT_MSG  XCB_COMPOSITE_LIBRARIES   XCB_COMPOSITE_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_DAMAGE      DEFAULT_MSG  XCB_DAMAGE_LIBRARIES      XCB_DAMAGE_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_XFIXES      DEFAULT_MSG  XCB_XFIXES_LIBRARIES      XCB_XFIXES_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_RENDER      DEFAULT_MSG  XCB_RENDER_LIBRARIES      XCB_RENDER_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_RANDR       DEFAULT_MSG  XCB_RANDR_LIBRARIES       XCB_RANDR_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_SHAPE       DEFAULT_MSG  XCB_SHAPE_LIBRARIES       XCB_SHAPE_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_DRI2        DEFAULT_MSG  XCB_DRI2_LIBRARIES        XCB_DRI2_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_GLX         DEFAULT_MSG  XCB_GLX_LIBRARIES         XCB_GLX_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_SHM         DEFAULT_MSG  XCB_SHM_LIBRARIES         XCB_SHM_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_XV          DEFAULT_MSG  XCB_XV_LIBRARIES          XCB_XV_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_SYNC        DEFAULT_MSG  XCB_SYNC_LIBRARIES        XCB_SYNC_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_XTEST       DEFAULT_MSG  XCB_XTEST_LIBRARIES       XCB_XTEST_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_ICCCM       DEFAULT_MSG  XCB_ICCCM_LIBRARIES       XCB_ICCCM_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_EWMH        DEFAULT_MSG  XCB_EWMH_LIBRARIES        XCB_EWMH_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_IMAGE       DEFAULT_MSG  XCB_IMAGE_LIBRARIES       XCB_IMAGE_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_RENDERUTIL  DEFAULT_MSG  XCB_RENDERUTIL_LIBRARIES  XCB_RENDERUTIL_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(XCB_KEYSYMS     DEFAULT_MSG  XCB_KEYSYMS_LIBRARIES     XCB_KEYSYMS_INCLUDE_DIR)

  MARK_AS_ADVANCED(
        XCB_INCLUDE_DIR             XCB_LIBRARIES
        XCB_XCB_INCLUDE_DIR         XCB_XCB_LIBRARIES
        XCB_UILT_INCLUDE_DIR        XCB_UTIL_LIBRARIES
        XCB_COMPOSITE_INCLUDE_DIR   XCB_COMPOSITE_LIBRARIES
        XCB_DAMAGE_INCLUDE_DIR      XCB_DAMAGE_LIBRARIES
        XCB_XFIXES_INCLUDE_DIR      XCB_XFIXES_LIBRARIES
        XCB_RENDER_INCLUDE_DIR      XCB_RENDER_LIBRARIES
        XCB_RANDR_INCLUDE_DIR       XCB_RANDR_LIBRARIES
        XCB_SHAPE_INCLUDE_DIR       XCB_SHAPE_LIBRARIES
        XCB_DRI2_INCLUDE_DIR        XCB_DRI2_LIBRARIES
        XCB_GLX_INCLUDE_DIR         XCB_GLX_LIBRARIES
        XCB_SHM_INCLUDE_DIR         XCB_SHM_LIBRARIES
        XCB_XV_INCLUDE_DIR          XCB_XV_LIBRARIES
        XCB_SYNC_INCLUDE_DIR        XCB_SYNC_LIBRARIES
        XCB_XTEST_INCLUDE_DIR       XCB_XTEST_LIBRARIES
        XCB_ICCCM_INCLUDE_DIR       XCB_ICCCM_LIBRARIES
        XCB_EWMH_INCLUDE_DIR        XCB_EWMH_LIBRARIES
        XCB_IMAGE_INCLUDE_DIR       XCB_IMAGE_LIBRARIES
        XCB_RENDERUTIL_INCLUDE_DIR  XCB_RENDERUTIL_LIBRARIES
        XCB_KEYSYMS_INCLUDE_DIR     XCB_KEYSYMS_LIBRARIES
  )

ENDIF (NOT WIN32)
